package com.zrspring.libv2.base;

/*   
 * Copyright (c) 2014-2014 China.ChongQing.MaiQuan Ltd All Rights Reserved.   
 *   
 * This software is the confidential and proprietary information of   
 * Founder. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with Founder.   
 *   
 */

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

/**
 * @ClassName: BaseActivity
 * @Description: 自定义activity类， 执行顺序 onCreate() > iniLayout() > iniView() >
 *               findExtraData() > loadData(); onDestroy() > cleanMemory()
 * @author 请填写作者名
 * @date 2014-5-25 下午5:45:10
 * @ConputerUserName zrspring
 */

public abstract class BaseFragmetActivity extends FragmentActivity {

	/**
	 * @Fields progressDialog :数据加载进度条
	 */
	private ProgressDialog progressDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		setStatusBarTransparent();
		setContentView(iniLayout());
		iniView();
		findExtraData();
		loadData();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		closeProgressDialog();
		cleanMenory();
	}

	/**
	 * @Title: setStatusBarTransparent @Description: 对大于4.4的OS设置状态栏透明 @throws
	 */
	public void setStatusBarTransparent() {
		if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
			//透明TOP状态栏 
			getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);  
	        //透明Buttom导航栏  
	        // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 
		}
	}

	/**
	 * @Title: iniLayout @Description: 设置布局文件 @return @throws
	 */
	public abstract int iniLayout();

	/**
	 * @Title: iniView @Description: 初始化界面，和配置熟悉，并添加监听等 @throws
	 */
	public abstract void iniView();

	/**
	 * @Title: findExtraData @Description: 获取intent里面的数据 @throws
	 */
	public abstract void findExtraData();

	/**
	 * @Title: loadData @Description: 加载数据，调用服务器数据，或者数据库等 @throws
	 */
	public abstract void loadData();

	/**
	 * @Title: cleanMemory @Description: 清空内存工作 @throws
	 */
	public abstract void cleanMenory();

	/**
	 * @Title: showToast @Description: @throws
	 */
	protected void showToast(String msg) {
		Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
	}

	protected void showToastIsDevelopmenting() {
		Toast.makeText(this, "功能正在开发中", Toast.LENGTH_SHORT).show();
	}
	
	/**
	 * @Title: openProgressDialog @Description: 打开进度条 @param title @param
	 * desc @throws
	 */
	protected void openProgressDialog(String title, String desc) {
		if (progressDialog == null) {
			progressDialog = new ProgressDialog(this);
			progressDialog.setTitle(title);
			progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			progressDialog.setMessage(desc);
			progressDialog.setCancelable(false);
			progressDialog.show();
		} else {
			progressDialog.show();
		}
	}

	/**
	 * @Title: closeProgressDialog @Description: 关闭进度条 @throws
	 */
	protected void closeProgressDialog() {
		if (progressDialog != null) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}
}
